package xyz.xpman.prisonerfitness.kit;

import org.jetbrains.annotations.NotNull;

import java.util.Timer;
import java.util.TimerTask;

public enum TimerKit {
    DEFAULT(new Timer());

    private final Timer timer;

    TimerKit(@NotNull Timer timer) {
        this.timer = timer;
    }

    public interface Task {
        void run();
    }


    public TimerTask schedule(@NotNull TimerKit.Task task, long delay) {
        final TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                task.run();
            }
        };

        timer.schedule(timerTask, delay);
        return timerTask;
    }

    public TimerTask schedule(@NotNull TimerKit.Task task, long delay, long period) {
        final TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                task.run();
            }
        };

        timer.schedule(timerTask, delay, period);
        return timerTask;
    }


    public void schedule(@NotNull TimerTask task, long delay) {
        timer.schedule(task, delay);
    }


    public void schedule(@NotNull TimerTask task, long delay, long period) {
        timer.schedule(task, delay, period);
    }

}
